#include "fwGameContent.h"
#include "..\Platform\fwPlatformFactory.h"

GameContent::GameContent()
	: m_bIsQuit(false)
{
	LOGIDBG("Init GameContext\n");
}

GameContent::~GameContent()
{
	LOGIDBG("Destroy GameContext\n");
}

FWint GameContent::Init(FWuint id, FWuint iWidth, FWuint iHeight, char * szTitle, FWuint iFlags)
{
	return PlatformFactory::GetInstance()->CreatePlatform(id, iWidth, iHeight, szTitle, iFlags)->Init();
}

void GameContent::Destroy()
{
	MessageService::DestroyInstance();
	PlatformFactory::DestroyInstance();
	StateManager::DestroyInstance();
}

void GameContent::Run(FWfloat deltaTime, FWboolean reset)
{
	if (reset)
	{
		Update(deltaTime);
		Draw();
	}
	else
	{
		MessageService::GetInstance()->SendMessageTag(this, "START_DEVICE", this);
		TagControll::Instance->SendTag(this, FW_START_GAME_EVENT, this);
	}
}

void GameContent::Quit()
{
	m_bIsQuit = true;
}

//============New Define=============//
FWint IGame::Init(FWuint id, FWuint iWidth, FWuint iHeight, char * szTitle, FWuint iFlags)
{
	_iWidth = iWidth;
	_iHeight = iHeight;
	return PlatformFactory::GetInstance()->CreatePlatform(id, iWidth, iHeight, szTitle, iFlags)->Init();
}

void IGame::Destroy()
{
	MessageService::DestroyInstance();
	PlatformFactory::DestroyInstance();
	StateManager::DestroyInstance();
}

void IGame::Start()
{
	//Start game
	//TODO: Send message start
	TagControll::Instance->SendTag(this, FW_START_GAME_EVENT, this);
	m_bIsActived = true;
	m_bIsPaused = false;
}

void IGame::End()
{
	//End game
	//TODO: Send message end game
	MessageService::GetInstance()->SendMessageTag(this, "END_GAME", NULL);
	m_bIsActived = false;
	Destroy();
}

void IGame::Pause()
{
	//TODO: Send message pause
	MessageService::GetInstance()->SendMessageTag(this, "PAUSE_GAME", NULL);
	m_bIsPaused = true;
}

void IGame::Resume()
{
	//TODO: Send message resume
	MessageService::GetInstance()->SendMessageTag(this, "RESUME_GAME", NULL);
	m_bIsPaused = false;
}